home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / macabuse / inc / stack.hpp < prev    next >
C/C++ Source or Header  |  1997-05-20  |  760b  |  42 lines

  1. #ifndef __STACK_HPP_
  2. #define __STACK_HPP_
  3.  
  4. #ifndef NO_LIBS
  5. #include "jmalloc.hpp"
  6.  
  7. #include "dprint.hpp"
  8. #else
  9. #include "fakelib.hpp"
  10. #endif
  11.  
  12. #include <stdio.h>
  13. struct cons_cell;
  14.  
  15. template<class T> class grow_stack        // stack does not shrink
  16.   public :
  17.   T **sdata;
  18.   long son;
  19.  
  20.   grow_stack(int max_size) { sdata=(T **)jmalloc(max_size,"pointer stack");  son=0; }
  21.   void push(T *data) 
  22.   {
  23.     sdata[son]=data;
  24.     son++;
  25.   }
  26.    
  27.   T *pop(long total) 
  28.   { if (total>son) { lbreak("stack underflow\n"); exit(0); }
  29.     son-=total;
  30.     return sdata[son];
  31.   }
  32.   void clean_up() 
  33.   { 
  34.     if (son!=0) dprintf("Warning cleaning up stack and not empty\n");
  35.     jfree(sdata); 
  36.     sdata=NULL;  son=0; 
  37.   }
  38. } ;
  39.  
  40. #endif
  41.